/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.jjsoft.celularessuc.gco.ui;

import com.jjsoft.celularessuc.gco.mdl.Factura;
import com.jjsoft.celularessuc.gco.mdl.Proforma;
import com.jjsoft.celularessuc.gco.mdl.Serviciotecnico;
import com.jjsoft.celularessuc.gco.util.CNumeros;
import com.jjsoft.celularessuc.gco.util.MiModelo;
import java.util.List;
import javax.swing.JOptionPane;
import javax.swing.JTextField;

/**
 *
 * @author johnny
 */
public class VBuscarPorCliente extends javax.swing.JFrame {

    /**
     * Creates new form VBuscarPorCliente
     */
    List<Factura> listaFacturas; 
    List<Proforma> listaProformas;
    List<Serviciotecnico> listaServicios;
    int tipo=0;
    public VBuscarPorCliente(List<Factura> listaFacturas) {
        
        this.setIconImage(new javax.swing.ImageIcon(getClass().getResource("/img/1362798841_CellPhone.png")).getImage());
        initComponents();
        this.dtgFacturas.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent e) {
                if (e.getClickCount() == 2) {
                    cmdAbrir.doClick();
                }
            }
        });
        this.listaFacturas=listaFacturas;
        String[] identificadores = {"NUMERO", "FECHA EMISION", "T. VENTA","SUCURSAL"};
        MiModelo modelo = new MiModelo();
        modelo.setColumnIdentifiers(identificadores);
        for(int i=0;i<listaFacturas.size();i++)
        {
            String [] fact ={String.valueOf(listaFacturas.get(i).getNumero()),listaFacturas.get(i).getFechaEmision().toLocaleString(),CNumeros.Formato(listaFacturas.get(i).getTotal()),listaFacturas.get(i).getIdSucursal().getNombre()};
            modelo.addRow(fact);
        }
        dtgFacturas.setModel(modelo);
    }
    public VBuscarPorCliente(List<Proforma> listaProformas,int a) {
        initComponents();
        tipo=a;
        this.dtgFacturas.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent e) {
                if (e.getClickCount() == 2) {
                    cmdAbrir.doClick();
                }
            }
        });
        this.listaProformas=listaProformas;
        lblTitulo.setText("PROFORMAS ENCONTRADAS");
        String[] identificadores = {"NUMERO","FECHA EMISION", "T. VENTA","SUCURSAL"};
        MiModelo modelo = new MiModelo();
        modelo.setColumnIdentifiers(identificadores);
        for(int i=0;i<listaProformas.size();i++)
        {
            String [] fact = {listaProformas.get(i).getNumero()+"",listaProformas.get(i).getFechaEmision().toLocaleString(),CNumeros.Formato(listaProformas.get(i).getTotal()),listaProformas.get(i).getIdSucursal().getNombre()};
            modelo.addRow(fact);
        }
        dtgFacturas.setModel(modelo);
    }
    public VBuscarPorCliente(List<Serviciotecnico> listaServicios,int a,int b) {
        
        initComponents();
        tipo=a;
        this.dtgFacturas.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent e) {
                if (e.getClickCount() == 2) {
                    cmdAbrir.doClick();
                }
            }
        });
        this.listaServicios=listaServicios;
        lblTitulo.setText("SERVICIOS TECNICOS ENCONTRADOS");
        String[] identificadores = {"NUMERO", "FECHA","DATOS DEL EQUIPO","SUCURSAL"};
        MiModelo modelo = new MiModelo();
        modelo.setColumnIdentifiers(identificadores);
        for(int i=0;i<listaServicios.size();i++)
        {
            String [] serv = {listaServicios.get(i).getIdServicioTecnico()+"",listaServicios.get(i).getFecha().toLocaleString(),listaServicios.get(i).getDatos(),listaServicios.get(i).getIdSucursal().getNombre()};
            modelo.addRow(serv);
        }
        dtgFacturas.setModel(modelo);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        dtgFacturas = new javax.swing.JTable();
        lblTitulo = new javax.swing.JLabel();
        cmdAbrir = new javax.swing.JButton();
        cmdCancelar = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        dtgFacturas.setAutoCreateRowSorter(true);
        dtgFacturas.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {},
                {},
                {},
                {}
            },
            new String [] {

            }
        ));
        dtgFacturas.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        jScrollPane1.setViewportView(dtgFacturas);

        lblTitulo.setFont(new java.awt.Font("Ubuntu", 1, 18)); // NOI18N
        lblTitulo.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lblTitulo.setText("Facturas Encontradas");

        cmdAbrir.setText("Abrir");
        cmdAbrir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmdAbrirActionPerformed(evt);
            }
        });

        cmdCancelar.setText("Cancelar");
        cmdCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmdCancelarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 562, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(cmdAbrir)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(cmdCancelar)
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addComponent(lblTitulo, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(lblTitulo)
                .addGap(18, 18, 18)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 199, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cmdAbrir)
                    .addComponent(cmdCancelar))
                .addContainerGap(14, Short.MAX_VALUE))
        );

        setSize(new java.awt.Dimension(598, 346));
        setLocationRelativeTo(null);
    }// </editor-fold>//GEN-END:initComponents

    private void cmdAbrirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmdAbrirActionPerformed
        // TODO add your handling code here:
        int i=dtgFacturas.getSelectedRow();
        if(i>=0)
        {
            if (tipo==0)
                new VVerFactura(listaFacturas.get(i)).setVisible(true);
            else if(tipo==1)
                new VServicioTecnico(listaServicios.get(i)).setVisible(true);
            else
                new VVerProforma(listaProformas.get(i)).setVisible(true);
        }
        else
        {
            JOptionPane.showMessageDialog(rootPane, "No ha seleccionado una factura","Error",JOptionPane.ERROR_MESSAGE);
        }
    }//GEN-LAST:event_cmdAbrirActionPerformed

    private void cmdCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmdCancelarActionPerformed
        // TODO add your handling code here:
        this.dispose();
    }//GEN-LAST:event_cmdCancelarActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(VBuscarPorCliente.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(VBuscarPorCliente.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(VBuscarPorCliente.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(VBuscarPorCliente.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new VBuscarPorCliente(null).setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton cmdAbrir;
    private javax.swing.JButton cmdCancelar;
    private javax.swing.JTable dtgFacturas;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JLabel lblTitulo;
    // End of variables declaration//GEN-END:variables
}
